﻿/* ==============================================================================
 * 功能描述：Map  
 * 
 * 创 建 者：郑镇泉
 * 
 * 创建日期：2016/4/17 21:39:40
 * ==============================================================================*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using ZZQFrameWork;

#region Map数据

public class TiledData
{
    public int width;
    public int height;
    public List<Layers> layers = new List<Layers>();
    public List<Tilesets> tilesets = new List<Tilesets>();

    public Tilesets GetTilesetsByName(string name)
    {
        for (int i = 0; i < tilesets.Count; i++)
        {
            if (tilesets[i].name == name)
            {
                return tilesets[i];
            }
        }
        return null;
    }
}

public class Layers
{
    public string name;
    public List<int> data = new List<int>();
    public int height;
    public int opacity;
    public string type;
    public bool visible;
    public int width;
    public int x;
    public int y;
}

public class Tilesets
{
    public int firstgid;
    public string image;
    public int imageheight;
    public int imagewidth;
    public int margin;
    public string name;
    public List<string> properties;
    public int spacing;
    public int tileheight;
    public int tilewidth;
}

#endregion


public class MapManager:Singleton<MapManager>
{
    //private string mapPath = Application.dataPath + "/StreamingAssets/Json/";

    private Dictionary<string,TextAsset> mapTextDic=new Dictionary<string, TextAsset>(); 

    public TextAsset GetMap(string name)
    {
        if (mapTextDic.ContainsKey(name))
        {
            return mapTextDic[name];
        }
        return LoadMap(name);
    }

    private TextAsset LoadMap(string name)
    {
        return Resources.Load<TextAsset>("Json/"+name);
    }
}